import Vue from 'vue';
import VueRouter  from 'vue-router';
import moduleOneRoutes from './modules/moduleOneRoutes'
import moduleTwoRouter from './modules/moduleTwoRoutes'

Vue.use(VueRouter );

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

// 通用/公用的单页面的路由
export const constantRoutes = [];

// 路由创建
const createRouter = () => new VueRouter ({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
});

const router = createRouter();

// 向路由中加入模块一的路由
router.addRoutes(moduleOneRoutes)

// 向路由中加入模块二的路由
router.addRoutes(moduleTwoRouter)

// 路由重置
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher;
}

export default router;
